package com.ruoyi.web.controller.gcgl;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gcgl.domain.SjCarservice;
import com.ruoyi.gcgl.service.ISjCarserviceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-26
 */
@Controller
@RequestMapping("/sj/carservice")
public class SjCarserviceController extends BaseController
{
    private String prefix = "sj/carservice";

    @Autowired
    private ISjCarserviceService sjCarserviceService;

    @RequiresPermissions("gcgl:carservice:view")
    @GetMapping()
    public String carservice()
    {
        return prefix + "/carservice";
    }

    /**
     * 查询车辆管理列表
     */
    @RequiresPermissions("gcgl:carservice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SjCarservice sjCarservice)
    {
        startPage();
        sjCarservice.setDeleteFlag(1);
        List<SjCarservice> list = sjCarserviceService.selectSjCarserviceList(sjCarservice);
        return getDataTable(list);
    }

    /**
     * 导出车辆管理列表
     */
    @RequiresPermissions("gcgl:carservice:export")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SjCarservice sjCarservice)
    {
    	sjCarservice.setDeleteFlag(1);
        List<SjCarservice> list = sjCarserviceService.selectSjCarserviceList(sjCarservice);
        ExcelUtil<SjCarservice> util = new ExcelUtil<SjCarservice>(SjCarservice.class);
        return util.exportExcel(list, "车辆管理数据");
    }

    /**
     * 新增车辆管理
     */
    @GetMapping("/add")
    public String add(ModelMap mmap){
    	mmap.put("user", getSysUser());
        return prefix + "/add";
    }

    /**
     * 新增保存车辆管理
     */
    @RequiresPermissions("gcgl:carservice:add")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SjCarservice sjCarservice)
    {
    	sjCarservice.setStatus(0);
    	sjCarservice.setDeleteFlag(1);
    	sjCarservice.setCreateUser(getLoginName());
    	sjCarservice.setCreateAt(new Date());
    	sjCarservice.setUpdateUser(getLoginName());
    	sjCarservice.setUpdateAt(new Date());
        return toAjax(sjCarserviceService.insertSjCarservice(sjCarservice));
    }

    /**
     * 修改车辆管理
     */
    @RequiresPermissions("gcgl:carservice:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SjCarservice sjCarservice = sjCarserviceService.selectSjCarserviceById(id);
        mmap.put("sjCarservice", sjCarservice);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆管理
     */
    @RequiresPermissions("gcgl:carservice:edit")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SjCarservice sjCarservice)
    {
    	sjCarservice.setUpdateUser(getLoginName());
    	sjCarservice.setUpdateAt(new Date());
        return toAjax(sjCarserviceService.updateSjCarservice(sjCarservice));
    }

    /**
     * 删除车辆管理
     */
    @RequiresPermissions("gcgl:carservice:remove")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sjCarserviceService.deleteSjCarserviceByIds(ids));
    }
}
